<cfsetting requestTimeOut = "5000"> 

<cfscript>    
    view = createObject("component", session.rootDir & ".views.layout");
    if( Session.Auth EQ True and (Session.strAuthType EQ Session.MANAGERS or Session.strAuthType EQ Session.IT or Session.strAuthType EQ Session.HR or Session.Manager) ){
        view.init("Contractor Expiration Date Extension", 
        "/jquery/ui-1.8.5/jquery-ui.min.js,/jquery/plugins/scrollTo/jquery.scrollTo-1.4.2-min.js, /#session.rootDir#/static/js/NonSCF/Review.js",
        "/jquery/ui-1.8.5/themes/cupertino/jquery-ui.css","Home",index, "Termination");
    }else{
        view.init("Denied","","","Home","Denied");
    }    
    view.html();
</cfscript>

<cffunction name="index" access="public" output="true" returntype="any">
    <cfscript>
        import models.*;
        FormActionExtend = '/#session.rootDir#/controller/SubmitHandlerTermination.cfm?NonSCFADAccount=extend';
        FormActionTerminate = '/#session.rootDir#/controller/SubmitHandlerTermination.cfm?NonSCFADAccount=terminate';
        KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
        AD = CreateObject("component", "code_lib.SCF_ActiveDirectory");
        PS = CreateObject("component", "code_lib.SCF_Powershell");        
    </cfscript>
    
    <cfset ManagerDN =  replace(replace(replace(AD.getUserDNByAccountName( session.userid ), "\", "\\", "all"), ",", "\,", "all"), "=", "\=", "all") />
    <!---<cfset ManagerDN =  replace(replace(replace(AD.getUserDNByAccountName( "dmlewis" ), "\", "\\", "all"), ",", "\,", "all"), "=", "\=", "all") />--->
    <cfldap 
        action="query" 
        attributes="displayname, sAMAccountName, manager, department, title, company, distinguishedName, accountExpires" 
        filter="(&(objectclass=user)(manager=#ManagerDN#))"
        username="scf\userlist" 
        password="DefinedMan" 
        name="contractors" 
        sort="displayname"
        start="OU=SCFUsers,DC=Southcentralfoundation,DC=COM" 
        server="10.100.1.101">
    
    <cfoutput>
    <h1 class="title">Contractor Expiration Date Extension</h1>
    <div class="entry">
        Welcome, #Session.EmpInfo.FirstName# #Session.EmpInfo.LastName#. 
        On this page, you'll be allowed to extend the expiration date for those 
        contractors that directly report to you.&nbsp;&nbsp;Accounts will expire 
        at the end of every month.&nbsp;&nbsp;To extend the operating window for 
        an additional month, select the option in the "Extend" column.&nbsp;
        &nbsp;There is a two week window prior to the end of each month where 
        this option will be available to you.&nbsp;&nbsp;If the contractor is no 
        longer with SCF, please select the "Terminate" option.&nbsp;&nbsp;If 
        there are additional contractors that report directly to you that are 
        not represented here, please contact the Service Desk at x5200.
        <br /><br />

        <cfform name="frmReview" method="post">
            <table  cellpadding="1" cellspacing="" width="100%">
                <tr>
                    <td><strong>Contractor Name</strong></td>
                    <td><strong>Company</strong></td>
                    <td><strong>Dept</strong></td>
                    <td><strong>Title</strong></td>
                    <td><strong>Expiration Date</strong></td>
                    <td><strong>Extend</strong></td>
                    <td><strong>Terminate*</strong></td>                
                </tr>
                
                <cfloop query="contractors">
                    <cfset Rosetta = ORMExecuteQuery("FROM RosettaStone WHERE UserAccount = '#replace(trim(contractors.sAMAccountName), "'", "`", "all")#'") />
                    <cfif ArrayLen(Rosetta) GTE 1 AND Rosetta[1].getNonSCFMasterID() NEQ "" AND Rosetta[1].getDisabled() EQ 0>
                        <cfset NonSCFMaster = entityLoadByPK("NonSCFMaster", Rosetta[1].getNonSCFMasterID()) />
                        <cfset EmployeeUserAccount = contractors.sAMAccountName />
                        <cfset EmployeeDN = contractors.distinguishedName />
                        <cfset Title = contractors.title />
                        <tbody id="#Rosetta[1].getNonSCFMasterID()#">
                            <cftry>
                                <cfset ExpirationDate = PS.usePowerShell('[dateTime]::FromFileTime($(#contractors.accountExpires#))') />
                                <cfset ExpirationDate = DateFormat(ExpirationDate, 'mm/dd/yyyy') />
                                <cfinput type="hidden" name="ExpirationDate" value="#ExpirationDate#">               
                            <cfcatch type="Any" >
                                <cfset ExpirationDate = '[Error]' />
                                <cfinput type="hidden" name="ExpirationDate" value="#ExpirationDate#">
                            </cfcatch>
                            </cftry>
                            <cfinput type="hidden" name="EmployeeUserAccount" value="#EmployeeUserAccount#">
                            <cfinput type="hidden" name="EmployeeDN" value="#EmployeeDN#">                        
                            <tr>
                                <td>#displayname#</td>
                                <td>#contractors.company#</td>
                                <td>#contractors.department#</td>
                                <td>#contractors.title#</td>
                                <td>#ExpirationDate#</td>
                                <td align="center">
                                    <cfif ExpirationDate NEQ '[Error]'>
                                        <cfinput type="radio" name="ExtendTerminate#Rosetta[1].getNonSCFMasterID()#" value="1" class="extend" />
                                    <cfelse>
                                        <strong class="error">NA</strong>
                                    </cfif>
                                </td>
                                <td align="center">
                                    <cfinput type="radio" name="ExtendTerminate#Rosetta[1].getNonSCFMasterID()#" value="2" class="terminate" />                                
                                </td>
                            </tr>
                        </tbody>
                    </cfif>
                </cfloop>
                <tr>
                    <td colspan="7" align="right">&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="7" align="right">
                        <cfinput type="button" name="Clear" value="Clear" />
                        <cfinput type="button" name="Submit" value="Submit" />
                        <cfinput type="hidden" name="FormActionExtend" value="#FormActionExtend#">
                        <cfinput type="hidden" name="FormActionTerminate" value="#FormActionTerminate#">
                    </td>
                </tr>
            </table>
        </cfform>
    </div>
    </cfoutput>
    
</cffunction>